import 'dart:io';

import 'package:jyofservice/jicha/JiChaGuanLi.dart';
import 'package:jyofservice/jicha/JiChaInfo.dart';
import 'package:jyofservice/jicha/ToDoJiCha.dart';
import 'package:jyofservice/main.dart';
import 'package:jyofservice/util/SlideRoute.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:dio/dio.dart';

class JiChaPage extends StatefulWidget {
  JiChaPage({Key? key}) : super(key: key);

  @override
  JiChaPageState createState() => JiChaPageState();
}

class JiChaPageState extends State<JiChaPage> {
  //稽查列表0,4数量
  int badgeCount = 0;

  //已处理1256数量
  int doneCount = 0;

  //稽查列表角标是否显示
  bool isTiXing = true;

  //已处理角标是否显示
  bool isTiXingDone = true;

  //0 待稽查 4待复核 1,2 稽查正常异常 5,6复核正常异常 51其他 21无法查看
  var stateStr = "0,4,1,2,5,6,51,21";
  var startTime = "";
  var endTime = "";
  bool isXGY = true;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    initData();
    getJiChaListData();
  }

  Future initData() async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    String? roleName = sharedPreferences.getString("rolename");
    if (roleName == "协管员") {
      isXGY = true;
    } else {
      isXGY = false;
    }
    if (mounted) {
      setState(() {});
    }
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Container(
          width: ScreenUtil().screenWidth,
          color: Colors.white,
          padding: EdgeInsets.fromLTRB(10, 5, 0, 5),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Container(
                width: ScreenUtil().setWidth(5),
                color: Colors.blue,
                height: ScreenUtil().setHeight(30),
              ),
              SizedBox(
                width: ScreenUtil().setWidth(15),
              ),
              Text(
                "收费稽查管理",
                style: TextStyle(
                    color: Colors.black87,
                    fontSize: ScreenUtil().setSp(30),
                    fontWeight: FontWeight.bold),
              )
            ],
          ),
        ),
        Container(
          color: Colors.black26,
          width: ScreenUtil().screenWidth,
          height: ScreenUtil().setHeight(1),
        ),
        Container(
            color: Colors.white,
            child: GridView.count(
              physics: new NeverScrollableScrollPhysics(),
              shrinkWrap: true,
              crossAxisCount: 4,
              childAspectRatio: 0.9,
              children: <Widget>[
                centerColumn_TiXing("images/yichuligongdan.png", "稽查信息",
                    isTiXingDone, doneCount),
                Offstage(
                  offstage: isXGY,
                  child: centerColumn_TiXing(
                      "images/jichaxingxi.png", "稽查列表", isTiXing, badgeCount),
                ),

              ],
            )),
        SizedBox(
          height: ScreenUtil().setHeight(20),
        ),
      ],
    );
  }

  TextButton centerColumn_TiXing(
      String asset, String label, bool isshow, int count) {
    return TextButton(
      onPressed: () {
        if (label == "稽查列表") {
          Navigator.of(context)
              .push(SlideRoute().createRoute(JiChaGuanLiPage()));
        } else if (label == "稽查信息") {
          Navigator.of(context).push(SlideRoute().createRoute(JiChaInfo()));
        }
      },
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Stack(
            alignment: Alignment(1.6, -1.5),
            children: <Widget>[
              Image.asset(
                asset,
                width: ScreenUtil().setWidth(110),
                height: ScreenUtil().setHeight(110),
              ),
              Offstage(
                offstage: isshow,
                child: Container(
                  alignment: Alignment.center,
                  width: ScreenUtil().setWidth(60),
                  height: ScreenUtil().setWidth(60),
                  decoration: BoxDecoration(
                    color: Colors.red,
                    borderRadius:
                        BorderRadius.circular(ScreenUtil().setWidth(30.0)),
                  ),
                  child: Text(
                    '${count > 999 ? "999+" : count.toString()}',
                    style: TextStyle(
                        fontSize: ScreenUtil().setSp(20),
                        color: Colors.white,
                        fontWeight: FontWeight.w500),
                  ),
                ),
              )
            ],
          ),
          SizedBox(
            height: ScreenUtil().setHeight(5),
          ),
          Text(
            label,
            style: TextStyle(
              fontSize: ScreenUtil().setSp(30),
              color: Colors.black,
            ),
          )
        ],
      ),
    );
  }

  //获取稽查列表数据
  Future getJiChaListData() async {}
}
